<template>
  <div class="help-container">
    <h2>请输入问题</h2>
    <input
      type="text"
      v-model="question"
      placeholder="在这里输入您的问题"
      :disabled="isSubmitting"
    />
    <button
      @click="getAnswer"
      :disabled="!question || isSubmitting"
    >
      提交
    </button>
    <div v-if="answer" class="answer">
      {{ answer }}
    </div>
  </div>
</template>

<style scoped>
.help-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  font-family: Arial, sans-serif;
}

h2 {
  margin-bottom: 10px;
  font-size: 20px;
  color: #333;
}

input {
  width: 80%;
  padding: 10px;
  margin: 10px 0;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 10px 20px;
  font-size: 16px;
  color: #fff;
  background-color: #007bff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

.answer {
  margin-top: 20px;
  font-size: 18px;
  color: #333;
}
</style>

<script>
const url = 'http://localhost:1000/';
export default {
  name: "Help",
  data() {
    return {
      question: '',
      answer: '',
      isSubmitting: false
    }
  },
  methods: {
    getAnswer() {
      this.isSubmitting = true;
      this.axios.post(url + "ai/backinfo?question=" + this.question).then(res => {
        console.log(res.data.data);
        this.answer = res.data.data;
      }).catch(err => {
        console.error(err);
      }).finally(() => {
        this.isSubmitting = false;
      });
    }
  }
}
</script>
